/*
 * Filename PreOrderMapping.java 2022年10月12日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.service.mapping;

import com.ehome.poct.core.api.constant.enums.CheckOrderStatus;
import com.ehome.poct.core.api.constant.enums.OrderType;
import com.ehome.poct.core.api.dto.check.TestRecordDetailDTO;
import com.ehome.poct.core.api.dto.check.TestReportDataConfigDTO;
import com.ehome.poct.core.api.dto.order.PrePlaceOrderDTO;
import com.ehome.poct.core.api.dto.order.TestOrderCheckRecordDTO;
import com.ehome.poct.core.api.dto.order.TestOrderDTO;
import com.ehome.poct.core.api.dto.order.TestOrderItemDTO;
import com.ehome.poct.core.api.dto.patient.TermPatientDTO;
import com.ehome.poct.core.api.vo.order.PrePatientVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wyc
 * @since 2022/10/12 17:25
 **/
@Mapper(componentModel = "spring", imports = {OrderType.class, CheckOrderStatus.class})
public interface PreOrderMapping {
    @Mapping(target = "orderItemName", source = "config.reportName")
    @Mapping(target = "testReportTypeCode", source = "config.reportCode")
    @Mapping(target = "testPoctReportType", source = "config.reportType")
    @Mapping(target = "stripTypeCode", source = "stripTypeCode")
    @Mapping(target = "map", ignore = true)
    @Mapping(target = "promotionProductCode", source = "config.promotionProductCode")
    TestOrderItemDTO to(TestReportDataConfigDTO config, Integer stripTypeCode, BigDecimal fee, String testOrderNo);

    @Mapping(target = "testOrderNo", source = "preOrder.orderNo")
    @Mapping(target = "name", source = "preOrder.orderName")
    @Mapping(target = "note", source = "preOrder.note")
    @Mapping(target = "clinicId", source = "preOrder.clinicId")
    @Mapping(target = "status", expression = "java(CheckOrderStatus.TO_PAY_AND_CHECK.getCode())")
    @Mapping(target = "orderType", expression = "java(OrderType.NORMAL.getType())")
    @Mapping(target = "payMoney", source = "totalMoney")
    @Mapping(target = "totalMoney", source = "totalMoney")
    @Mapping(target = "isPay", constant = "false")
    @Mapping(target = "discountMoney", constant = "0")
    @Mapping(target = "couponMoney", constant = "0")
    @Mapping(target = "promotionMoney", constant = "0")
    @Mapping(target = "freightMoney", constant = "0")
    TestOrderDTO to(PrePlaceOrderDTO preOrder, BigDecimal totalMoney, Integer sourceType, List<TestOrderItemDTO> items);

    @Mapping(target = "status", constant = "0")
    TestOrderCheckRecordDTO to(PrePlaceOrderDTO dto, Integer testType, Integer isUni, String testItemCode, String reservationCode);

    @Mapping(target = "map", ignore = true)
    @Mapping(target = "isPay", constant = "false")
    @Mapping(target = "testMoney", source = "item.fee")
    @Mapping(target = "deviceType", source = "deviceType")
    TestRecordDetailDTO to(TestOrderItemDTO item, BigDecimal testPeoplePortion, PrePlaceOrderDTO dto, Integer deviceType);

    PrePatientVO to(TermPatientDTO dto);
}